/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package usuario.control;

import usuario.frames.*;
import bibliinfo.FrameMain;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import usuario.model.ValidaUsuario;

/**
 *
 * @author Ar0n
 */
public class UserFrameDadosAddUpdate extends javax.swing.JInternalFrame {

    /**
     * Creates new form UserFrameDadosSalve
     */
    public UserFrameDadosAddUpdate() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365869813_restart-1.png"))); // NOI18N
        jButton2.setText("Dados Usuário");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365683699_window-close.png"))); // NOI18N
        jButton3.setText("Cancelar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365288060_3floppy_umount.png"))); // NOI18N
        jButton1.setText("Salvar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 185, Short.MAX_VALUE)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(61, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        
       FrameMain.userFrameDados.setVisible(false);
       FrameMain.userFrameDados.setEstado(false);
       
       FrameMain.userFrameMain.setVisible(true);
       FrameMain.userFrameMain.setEstado(true); 
        
        //retirando bordas do internalJframe           
       ((BasicInternalFrameUI)FrameMain.userFrameMain.getUI()).setNorthPane(null);
       FrameMain.userFrameMain.setBorder(null);        
       //pegando dimenções do JFrame no qual ele esta encapsulado
       FrameMain.userFrameMain.setBounds(0, 0, FrameMain.jDesktop.getWidth(), FrameMain.jDesktop.getHeight());        
       FrameMain. userFrameMain.setResizable(false);
       FrameMain.userFrameMain.setBorder(null); 
        
       
        
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        FrameMain.userFrameAdd.setVisible(false);
        FrameMain.userFrameAdd.setEstado(false);

        FrameMain.userFrameDados.setVisible(true);
        FrameMain.userFrameDados.setEstado(true);        
        FrameMain.formata(12);
        FrameMain.userFrameDados.setComponente(3);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        ValidaUsuario validarUsuario = new ValidaUsuario();
        boolean resp = validarUsuario.validaUserUpdate(FrameMain.userFrameDados.getRgAntigo(), FrameMain.userFrameDados.jTRG, FrameMain.userFrameDados.jTNome,
                FrameMain.userFrameDados.jTCidade, FrameMain.userFrameDados.jTCep, FrameMain.userFrameDados.jTBairro,
                FrameMain.userFrameDados.jTRua, FrameMain.userFrameDados.jTNumCasa, FrameMain.userFrameDados.jTDia,
                FrameMain.userFrameDados.jTMes, FrameMain.userFrameDados.jTAno);
        
        if(resp == true){
            
            resp = validarUsuario.validarAdd(FrameMain.userFrameAdd.jTDataCadDia, FrameMain.userFrameAdd.jTDataCadMes,
                    FrameMain.userFrameAdd.jTDataCadAno, FrameMain.userFrameAdd.jRBSim.isSelected(), FrameMain.userFrameAdd.jTDataInicioDia, FrameMain.userFrameAdd.jTDataInicioMes,
                    FrameMain.userFrameAdd.jTDataInicioAno, FrameMain.userFrameAdd.jTDataFimDia, FrameMain.userFrameAdd.jTDataFimMes,
                    FrameMain.userFrameAdd.jTDataFimAno);
            
            if(resp == true){
               UserFrameDadosUpdate up = new UserFrameDadosUpdate();
               up.atualizarUser();
            }            
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    // End of variables declaration//GEN-END:variables
}
